<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'list.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
  <script type="text/javascript">
  	$(function(){
  		
  	});
  	function view(id) {
  		$.ajax({
  			url:'devUsers/' + id,
  			dataType:'json',
  			success:function(user) {
  				$("#userinfo").html("");
  				$("#userinfo").append("<ul>");
  				$("#userinfo").append("<li>"+user.id+"</li>");
  				$("#userinfo").append("<li>"+user.devCode+"</li>");
  				$("#userinfo").append("<li>"+user.devName+"</li>");
  				$("#userinfo").append("<li>"+user.devPassword+"</li>");
  				$("#userinfo").append("<li>"+user.devEmail?user.devEmail:""+"</li>");
  				$("#userinfo").append("<li>"+user.devInfo?user.Info:""+"</li>");
  				$("#userinfo").append("</ul>");
  			},
  			error:function(xhr) {
  				alert('出错了');
  			}
  		});
  	}
  	function del(id) {
  		$.getJSON('devUsers/del/' + id,function(result){
  			alert(result?"删除成功":"删除失败");
  			if(result) {
  				location.href='devUsers';
  			}
  		});
  	}
  </script>
  </head>
  
  <body>
  	<button onclick="location.href='devUsers/add'">添加</button>
    <table border="1">
    	<tr>
    		<td>id</td>
    		<td>devCode</td>
    		<td>devName</td>
    		<td>devPassword</td>
    		<td>devEmail</td>
    		<td>devInfo</td>
    		<td>操作</td>
    	</tr>
    	<c:forEach var="user" items="${devUsers}">
    		<tr>
    		<td>${user.id}</td>
    		<td><a href="javascript:view(${user.id})">${user.devCode}</a></td>
    		<td>${user.devName}</td>
    		<td>${user.devPassword}</td>
    		<td>${user.devEmail}</td>
    		<td>${user.devInfo}</td>
    		<td>
    			<a href="devUsers/update/${user.id}">修改</a>
    			<a href="javascript:del(${user.id})" onclick="return confirm('确定要删除吗？')">删除</a>
    		</td>
    	</tr>
    	</c:forEach>
    </table>
    <div id="userinfo"></div>
  </body>
</html>
